<?php
namespace jy_mjifee;
defined('BY_JYA') or exit('error');
/*
	分销插件工具类
*/
class model extends \plugin{
	
	public function checklogin(){
		cfc('core')->checklogin();
		$this->model('member')->register();
	}
	public function current_level_up_types($merchid=0){
		if($merchid){
			$this->setting=$this->plugin_setting('setting'.$merchid);
		}
		return str_array($this->setting['level_up_types']);
	}
	public function current_daili_file_types(){
		return str_array($this->setting['daili_file']);
	}
	/*
		单品销售额
	*/
	public function goods_allfee($member=array(),$mid=0,$ismonth=0,$goods_id=0){
		$mid=$mid?:$member['mid'];
		$mid=$mid?:$_SESSION['uid'];
		$member['merchid']=$member['merchid']?:$_SESSION['onemerchid'];
		$total_price=0;
		$params=array('merchid'=>$member['merchid'],'uniacid'=>$_SESSION['uniacid']);
		if(!$goods_id){
			$goodsids=pdo_getall('jy_mjifee_goods',$params,array('goods_id'),'goods_id');
			if($goodsids){
				$goodsids=array_keys($goodsids);
			}else{
				$goodsids=-1;
			}
			$params['goodsid']=$goodsids;
		}else{
			$params['goodsid']=$goods_id;
		}
		$params['ispay']=1;
		if($ismonth){
			if($ismonth==2){
				$lasttime=strtotime('-1 month');
				$month_start=strtotime(date('Ym').'01');
				$params['createtime between']=array($lasttime,$month_start);	
			}else{
				$month_start=strtotime(date('Ym').'01');
				$params['createtime >']=$month_start;
			}
		}
		if($member['level']['type']==1){
			$mids=pdo_getall('core_members',array('fromuser'=>$mid,'uniacid'=>$_SESSION['uniacid']),array('id'),'id');
			if($mids){
				$mids=array_keys($mids);
				$mids[]=$mid;
			}else{
				$mids=$mid;
			}
			$params['mid']=$mids;
			$total_price=pdo_getsum('jy_mjifee_order_goods',$params,'total_price');
		}elseif($member['level']['type']==2){
			$params['bumenid']=$member['bumenid'];
			$total_price=pdo_getsum('jy_mjifee_order_goods',$params,'total_price');
		}elseif($member['level']['type']==3){
			$total_price=pdo_getsum('jy_mjifee_order_goods',$params,'total_price');
		}
		$total_price=intval($total_price*100)/100;
		return $total_price;
	}
}